package 面向对象;

//拼接字符串
// 定义一个方法，把数组{1,2,3}按照指定格式拼接成一个字符串。
public class test2 {
    public static void main(String[] args) {
        int [] a = {2,8,9,5,6,22,11};
        String zxc = arrayToString(a);
        System.out.println(zxc);
    }
    public static String arrayToString(int [] a) {
        if(a.length == 0){
            return "[]";
        }
        if(a == null ){
            return "";
        }
        String result ="[";
        for (int i = 0; i < a.length; i++) {
            if (i>0 && i < a.length-1){
                result =result + a[i]+", ";
            }else if(i ==a.length -1){
                result =result + a[i];
            }
        }
        result =result +"]";
        return result;

    }
}
